import { Controller, Get, Post, Body, Patch, Param, Delete, ParseIntPipe } from '@nestjs/common';
import { FriendshipService } from './friendship.service';
import { CreateFriendshipDto } from './dto/create-friendship.dto';
import { UpdateFriendshipDto } from './dto/update-friendship.dto';
import { RequireLogin, UserInfo } from 'src/decorator/custom.decorator';

@Controller('friendship')
export class FriendshipController {
    constructor(private readonly friendshipService: FriendshipService) {}

    // 发起添加好友申请
    @Post('add')
    @RequireLogin()
    async add(@Body() friendAddDto: CreateFriendshipDto, @UserInfo("userId") userId: number) {
        return this.friendshipService.add(friendAddDto, userId);
    }

    // 同意添加  内置管道 ParseIntPipe 转为数字
    @Post('agree/:id')
    @RequireLogin()
    async agree(@Param('id', ParseIntPipe ) friendId:number , @UserInfo("userId") userId: number ) {

        return this.friendshipService.agree(friendId , userId);
    }

    // 拒绝添加
    @Post('reject/:id')
    @RequireLogin()
    async reject(@Param('id' , ParseIntPipe) friendId:number ,@UserInfo("userId") userId: number ) {
        return this.friendshipService.reject(friendId, userId);
    }

    // 删除好友
    @Post('remove/:id')
    @RequireLogin()
    async remove(@Param("id" , ParseIntPipe ) friendId:number , @UserInfo("userId") userId:number ){
        return this.friendshipService.remove(friendId , userId)
    }

    // 接收好友列表
    @Post('accept')
    @RequireLogin()
    addlist(@UserInfo("userId") userId:number){
        return this.friendshipService.acceptlist(userId)
    }


    // 发送好友列表
    @Post('send')
    @RequireLogin()
    send(@UserInfo("userId") userId:number){
        return this.friendshipService.send(userId)
    }
}
